map = new AMap.Map("map", {
  // zoom: 9.5,
  // center: [112.85000, 36.392438],
  center: [112.978606, 36.867027],
  zoom: 11,
  pitch: 50,
  mapStyle: "amap://styles/grey",
  viewMode: "3D",
});
function addPolygon(data) {
  let polygon = new AMap.Polygon({
    path: data,
    fillColor: "#ccebc5",
    strokeOpacity: 1,
    fillOpacity: 0,
    strokeColor: "#5341fd",
    strokeWeight: 2,
    strokeStyle: "dashed",
    strokeDasharray: [5, 5],
  });
  map.add(polygon);
}
addPolygon(wuxiang);
loca = new Loca.Container({
  map,
});
// AMap.plugin([
//     'AMap.ControlBar',
// ], function () {
//     map.addControl(new AMap.ControlBar({
//         position: {
//             right: '420rem',
//             bottom: '180rem'
//         },
//         showControlButton: true,
//     }));
// });
// AMap.plugin([
//     'AMap.ToolBar',
// ], function () {
//     map.addControl(new AMap.ToolBar({
//         position: {
//             right: '450rem',
//             bottom: '90rem'
//         },
//     }));
// });
// var loca = new Loca.Container({
//   map,
// });

var hotItem = document.getElementById("hot-con_table_container"); // 热门事项列表滚动区域元素
var hotItemCon = document.getElementById("hotCon"); // 热门事项列表元素
var hotItemSpeed = 50; // 热门事项滚动速度
$(function () {
  // 累计办理数据
  getHadHelpData();
  // 政务类办件统计
  getHadGovernmentData();
  //秒批秒办类统计
  getHadSecondData();
  //证明类
  getHadProveData();
  // 查询类
  getHadQueryData();
  //   便民工具类
  getHadToolsData();
  // 事项发布统计  政务服务类 秒批秒办类 证明类 查询类 便民工具类
  getItemIssueCountData();
  // 各乡镇办件量统计
  getPerTownHelpData("");
  // 各乡镇办件量统计类型切换
  $(".perTownCount>div").click(function () {
    $(this).parents(".perTownCount").find("div").removeClass("active");
    $(this).addClass("active");
    var type = $(this).attr("data-type");
    getPerTownHelpData(type);
  });
  // 各乡镇事项发布数统计
  getPerTownIssueData("");
  // 各乡镇事项发布统计类型切换
  $(".perTownIssueCount>div").click(function () {
    $(this).parents(".perTownIssueCount").find("div").removeClass("active");
    $(this).addClass("active");
    var type = $(this).attr("data-type");
    getPerTownIssueData(type);
  });
  // 热门事项
  getHotItemData();
});
// 累计办理数据
function getHadHelpData() {
  let allHadGovernment = document.getElementById("allHadGovernment"); //政务服务类累计办理
  let allHadSecond = document.getElementById("allHadSecond"); //秒批秒办类累计办理
  let allHadProve = document.getElementById("allHadProve"); //证明类累计办理
  let allHadQuery = document.getElementById("allHadQuery"); //查询类累计查询
  let allHadTools = document.getElementById("allHadTools"); //便民工具类累计使用
  $.ajax({
    url: url + "/api/v1/business/businessOverviewNum",
    type: "get",
    headers: headers,
    success: function (data) {
      if (data.success) {
        valueFlash(allHadGovernment, data.data.ZW, 1);
        valueFlash(allHadSecond, 0, 1);
        valueFlash(allHadProve, data.data.ZM, 1);
        valueFlash(allHadQuery, data.data.CX, 1);
        valueFlash(allHadTools, data.data.BMGJ, 1);
      }
    },
  });
}
// 政务类办件统计
function getHadGovernmentData() {
  let goverYear = document.getElementById("goverYear"); //政务服务类本年办件
  let goverMonth = document.getElementById("goverMonth"); //政务服务类本月办件
  let goverWeek = document.getElementById("goverWeek"); //政务服务类本周办件
  $.ajax({
    url: url + "/api/v1/business/govBusinessNum",
    type: "get",
    headers: headers,
    success: function (data) {
      if (data.success) {
        valueFlash(goverYear, data.data.BN, 1);
        valueFlash(goverMonth, data.data.BYY, 1);
        valueFlash(goverWeek, data.data.BZ, 1);
      }
    },
  });
}
//秒批秒办类统计
function getHadSecondData() {
  let secondYear = document.getElementById("secondYear"); //秒批秒办类本年办件
  let secondMonth = document.getElementById("secondMonth"); //秒批秒办类本月办件
  let secondWeek = document.getElementById("secondWeek"); //秒批秒办类本周办件
  valueFlash(secondYear, 0, 1);
        valueFlash(secondMonth, 0, 1);
        valueFlash(secondWeek, 0, 1);
  // $.ajax({
  //   url: url + "/api/v1/business/handleBySecond",
  //   type: "get",
  //   headers: headers,
  //   success: function (data) {
  //     if (data.success) {
  //       valueFlash(secondYear, 0, 1);
  //       valueFlash(secondMonth, 0, 1);
  //       valueFlash(secondWeek, 0, 1);
  //     }
  //   },
  // });
}
//证明类统计
function getHadProveData() {
  let proveYear = document.getElementById("proveYear"); //证明类本年办件
  let proveMonth = document.getElementById("proveMonth"); //证明类本月办件
  let proveWeek = document.getElementById("proveWeek"); //证明类本周办件
  $.ajax({
    url: url + "/api/v1/business/provitionBusinessNum",
    type: "get",
    headers: headers,
    success: function (data) {
      if (data.success) {
        valueFlash(proveYear, data.data.BN, 1);
        valueFlash(proveMonth, data.data.BYY, 1);
        valueFlash(proveWeek, data.data.BZ, 1);
      }
    },
  });
}
// 查询类
function getHadQueryData() {
  let queryYear = document.getElementById("queryYear"); //查询类本年办件
  let queryMonth = document.getElementById("queryMonth"); //查询类本月办件
  let toolsWeek = document.getElementById("queryWeek"); //查询类本周办件
  $.ajax({
    url: url + "/api/v1/business/covBusinessNum",
    type: "get",
    headers: headers,
    data: {
      queryType: "cx",
    },
    success: function (data) {
      if (data.success) {
        valueFlash(queryYear, data.data.BN, 1);
        valueFlash(queryMonth, data.data.BYY, 1);
        valueFlash(queryWeek, data.data.BZ, 1);
      }
    },
  });
}
//   便民工具类
function getHadToolsData() {
  let toolsYear = document.getElementById("toolsYear"); //便民工具类本年办件
  let toolsMonth = document.getElementById("toolsMonth"); //便民工具类本月办件
  let toolsWeek = document.getElementById("toolsWeek"); //便民工具类本周办件
  $.ajax({
    url: url + "/api/v1/business/covBusinessNum",
    type: "get",
    headers: headers,
    data: {
      queryType: "bmgj",
    },
    success: function (data) {
      if (data.success) {
        valueFlash(toolsYear, data.data.BN, 1);
        valueFlash(toolsMonth, data.data.BYY, 1);
        valueFlash(toolsWeek, data.data.BZ, 1);
      }
    },
  });
}
// 事项发布统计
function getItemIssueCountData() {
  let goverCount = document.getElementById("goverCount"); //政务服务类
  let secondCount = document.getElementById("secondCount"); //秒批秒办类
  let proveCount = document.getElementById("proveCount"); //证明类
  let queryCount = document.getElementById("queryCount"); //查询类
  let toolsCount = document.getElementById("toolsCount"); //便民工具类
  $.ajax({
    url: url + "/api/v1/business/itemIssueOverview",
    type: "get",
    headers: headers,
    success: function (data) {
      if (data.success) {
        valueFlash(goverCount, data.data.ZW, 1);
        // valueFlash(secondCount, data.data.MPMB, 1);
        valueFlash(secondCount, 33, 1);
        valueFlash(proveCount, data.data.ZM, 1);
        valueFlash(queryCount, data.data.CX, 1);
        valueFlash(toolsCount, data.data.BMGJ, 1);
      }
    },
  });
}
const chartIconList = [
  "../images/index/paiming_1.png",
  "../images/index/paiming_2.png",
  "../images/index/paiming_3.png",
  "../images/index/paiming_4.png",
  "../images/index/paiming_5.png",
  "../images/index/paiming_6.png",
  "../images/index/paiming_7.png",
  "../images/index/paiming_8.png",
  "../images/index/paiming_9.png",
  "../images/index/paiming_10.png",
  "../images/index/paiming_11.png",
  "../images/index/paiming_12.png",
  "../images/index/paiming_12.png",
  "../images/index/paiming_12.png",
  "../images/index/paiming_12.png",
  "../images/index/paiming_12.png",
  "../images/index/paiming_12.png",
  "../images/index/paiming_12.png",
];
// 各乡镇办件量统计
var thermodynamicChartData = {
  type: "FeatureCollection",
  features: [],
};

function getPerTownHelpData(type) {
  thermodynamicChartData.features = [];
  $.ajax({
    url: url + "/api/v1/business/businessNumByRegion",
    type: "get",
    headers: headers,
    data: { queryType: type },
    success: function (data) {
      if (data.success) {
        for (var i = 0; i < data.data.length; i++) {
          thermodynamicChartData.features.push({
            type: "Feature",
            geometry: {
              type: "Point",
              name: data.data[i].QHMC,
              coordinates: [
                Number(data.data[i].ZB.split(",")[0]),
                Number(data.data[i].ZB.split(",")[1]),
              ],
            },
            properties: {
              count: data.data[i].BJSL,
            },
          });
        }
        setPerTownCountMap(data.data);
        setThermodynamicChart(thermodynamicChartData);
      }
    },
  });
}
// 热力图地图打点
function setThermodynamicChart(data) {
  var heatmap = new Loca.HeatMapLayer({
    zIndex: 10,
    opacity: 1,
    visible: true,
    zooms: [2, 22],
  });
  var geo = new Loca.GeoJSONSource({
    data,
  });
  heatmap.setSource(geo, {
    radius: 5000,
    unit: "meter",
    // height: 1000,
    difference: true,
    gradient: {
      1: "#FF4C2F",
      0.8: "#FAA53F",
      0.6: "#FFF100",
      0.5: "#7DF675",
      0.4: "#5CE182",
      0.2: "#29CF6F",
    },
    value: function (index, feature) {
      return feature.properties.count;
    },
    opacity: [0, 0.8],
    heightBezier: [0, 0.53, 0.37, 0.98],
  });
  loca.clear();
  loca.add(heatmap);
}
function setPerTownCountMap(data) {
  var townCountChart = echarts.init(document.getElementById("perTownCount"));
  var option = {
    tooltip: {
      show: true,
      trigger: "item",
      padding: [8, 15],
      backgroundColor: "rgba(12, 51, 115,0.8)",
      borderColor: "rgba(3, 11, 44, 0.5)",
      textStyle: {
        color: "rgba(255, 255, 255, 1)",
      },
    },
    legend: {
      show: false,
    },
    grid: {
      left: "90",
      right: "16%",
      top: "0%",
      bottom: "0%",
    },
    xAxis: [
      {
        splitLine: {
          show: false,
        },
        type: "value",
        show: false,
      },
    ],
    yAxis: [
      {
        splitLine: {
          show: false,
        },
        axisLine: {
          show: false,
        },
        type: "category",
        axisTick: {
          show: false,
        },
        inverse: true,
        data: data.map((item) => item.QHMC),
        axisLabel: {
          color: "#fff",
          fontSize: 12,
          margin: 10,
          formatter: function (value, index) {
            return `{img${index}|}{value|${value}}`;
          },
          rich: {
            value: {
              width: 55,
            },
            img0: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[0],
              },
            },
            img1: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[1],
              },
            },
            img2: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[2],
              },
            },
            img3: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[3],
              },
            },
            img4: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[4],
              },
            },
            img5: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[5],
              },
            },
            img6: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[6],
              },
            },
            img7: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[7],
              },
            },
            img8: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[8],
              },
            },
            img9: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[9],
              },
            },
            img10: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[10],
              },
            },
            img11: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[11],
              },
            },
            img12: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[12],
              },
            },
            img13: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[13],
              },
            },
            img14: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[14],
              },
            },
            img15: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[15],
              },
            },
          },
        },
      },
      {
        type: "category",
        inverse: true,
        axisTick: "none",
        axisLine: "none",
        show: true,
        axisLabel: {
          textStyle: {
            color: "#fff",
            fontWeight: 700,
          },
          formatter: function (value) {
            return value;
          },
        },
        data: data.map((item) => item.BJSL),
      },
    ],
    series: [
      {
        name: "办件量",
        type: "bar",
        barWidth: 3, // 柱子宽度
        MaxSize: 0,
        showBackground: true,
        backgroundStyle: {
          color: "rgba(255, 255, 255, 0.1)",
        },
        label: {
          show: false,
        },
        data: data.map((item, index) => {
          return {
            name: item.QHMC,
            value: item.BJSL,
            itemStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 1,
                y2: 1,
                colorStops: [
                  {
                    offset: 1,
                    color: "rgba(0, 146, 255, 1)",
                  },
                  {
                    offset: 0,
                    color: "rgba(0, 58, 255, 0)",
                  },
                ],
              },
            },
          };
        }),
      },
      {
        name: "外圆",
        type: "scatter",
        emphasis: {
          scale: false,
        },
        symbol: "circle",
        symbolSize: [5, 5],
        itemStyle: {
          color: "#FFF",
          shadowColor: "#0092FF",
          shadowBlur: 5,
          borderWidth: 1,
          opacity: 1,
          borderColor: "#0092FF",
        },
        z: 2,
        data: data,
        animationDelay: 500,
      },
    ],
  };
  townCountChart.setOption(option);
}
// 各乡镇事项发布统计
function getPerTownIssueData(type) {
  $.ajax({
    url: url + "/api/v1/business/itemIssueNumByRegion",
    type: "get",
    headers: headers,
    data: { queryType: type },
    success: function (data) {
      if (data.success) {
        setPerTownIssueChart(data.data);
      }
    },
  });
}
function setPerTownIssueChart(data) {
  var perTownIssueChart = echarts.init(
    document.getElementById("perTownIssueCount")
  );
  var option = {
    tooltip: {
      show: true,
      trigger: "item",
      padding: [8, 15],
      backgroundColor: "rgba(12, 51, 115,0.8)",
      borderColor: "rgba(3, 11, 44, 0.5)",
      textStyle: {
        color: "rgba(255, 255, 255, 1)",
      },
    },
    legend: {
      show: false,
    },
    grid: {
      left: "90",
      right: "16%",
      top: "0%",
      bottom: "0%",
    },
    xAxis: [
      {
        splitLine: {
          show: false,
        },
        type: "value",
        show: false,
      },
    ],
    yAxis: [
      {
        splitLine: {
          show: false,
        },
        axisLine: {
          show: false,
        },
        type: "category",
        axisTick: {
          show: false,
        },
        inverse: true,
        data: data.map((item) => item.QHMC),
        axisLabel: {
          color: "#fff",
          fontSize: 12,
          margin: 10,
          formatter: function (value, index) {
            return `{img${index}|}{value|${value}}`;
          },
          rich: {
            value: {
              width: 55,
            },
            img0: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[0],
              },
            },
            img1: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[1],
              },
            },
            img2: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[2],
              },
            },
            img3: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[3],
              },
            },
            img4: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[4],
              },
            },
            img5: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[5],
              },
            },
            img6: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[6],
              },
            },
            img7: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[7],
              },
            },
            img8: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[8],
              },
            },
            img9: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[9],
              },
            },
            img10: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[10],
              },
            },
            img11: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[11],
              },
            },
            img12: {
              width: 24,
              height: 16,
              backgroundColor: {
                image: chartIconList[12],
              },
            },
          },
        },
      },
      {
        type: "category",
        inverse: true,
        axisTick: "none",
        axisLine: "none",
        show: true,
        axisLabel: {
          textStyle: {
            color: "#fff",
            fontWeight: 700,
          },
          formatter: function (value) {
            return value;
          },
        },
        data: data.map((item) => item.BJSL),
      },
    ],
    series: [
      {
        name: "事项发布数",
        type: "bar",
        barWidth: 3, // 柱子宽度
        MaxSize: 0,
        showBackground: true,
        backgroundStyle: {
          color: "rgba(255, 255, 255, 0.1)",
        },
        label: {
          show: false,
        },
        data: data.map((item, index) => {
          return {
            name: item.QHMC,
            value: item.BJSL,
            itemStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 1,
                y2: 1,
                colorStops: [
                  {
                    offset: 1,
                    color: "rgba(0, 146, 255, 1)",
                  },
                  {
                    offset: 0,
                    color: "rgba(0, 58, 255, 0)",
                  },
                ],
              },
            },
          };
        }),
      },
      {
        name: "外圆",
        type: "scatter",
        emphasis: {
          scale: false,
        },
        symbol: "circle",
        symbolSize: [5, 5],
        itemStyle: {
          color: "#FFF",
          shadowColor: "#0092FF",
          shadowBlur: 5,
          borderWidth: 1,
          opacity: 1,
          borderColor: "#0092FF",
        },
        z: 2,
        data: data,
        animationDelay: 500,
      },
    ],
  };
  perTownIssueChart.setOption(option);
}
// 热门事项
function getHotItemData() {
  var hotCaotainer = document.getElementById("hotCon");
  $.ajax({
    url: url + "/api/v1/business/hotItem",
    type: "get",
    headers: headers,
    success: function (data) {
      if (data.success) {
        var str = "";
        data.data.forEach(function (item, index) {
          str += "<tr>";
          if (index < 9) {
            str +=
              '<td style="width: 20%;font-style: italic;">0' +
              (index + 1) +
              "</td>";
          } else {
            str +=
              '<td style="width: 20%;font-style: italic;">' +
              (index + 1) +
              "</td>";
          }
          str +=
            '<td style="text-align:left;width: 60%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;padding-right: 10rem;">' +
            item.SXMC +
            "</td>" +
            '<td style="width: 20%;text-align:left">' +
            item.COUNT +
            "</td>" +
            "</tr>";
        });
        hotCaotainer.innerHTML = str;
        hotItemListRoll();
      }
    },
  });
}
// 停止滚动
function hotItemListRollStop() {
  if (hotItem.scrollTop >= hotItemCon.scrollHeight / 2) {
    hotItem.scrollTop = 0;
    hotItem.scrollTop = hotItem.scrollTop - hotItemCon.scrollHeight / 2;
  } else {
    hotItem.scrollTop++;
  }
}
// 热门事项滚动事件
function hotItemListRoll() {
  hotItemCon.innerHTML += hotItemCon.innerHTML; // 列表数据复制实现循环滚动
  hotItem.scrollTop++;
  hotItemTimer = setInterval(hotItemListRollStop, hotItemSpeed);
}
// 鼠标移入
hotItem.onmouseover = function () {
  clearInterval(hotItemTimer);
};
// 鼠标移除
hotItem.onmouseout = function () {
  hotItemTimer = setInterval(hotItemListRollStop, hotItemSpeed);
};
